<?php

function ListServiceCat($limit=0,$idP=0)
{
    global $dbsql,$language;
    $idP        = intval($idP);
	    
    $sql_select = "select ca.iId,ca.cName,ca.cImage,ca.cIntro from tblcategory as ca ";
    if($idP>0)
    {
        $sql_select .= " where ca.iParentId = $idP ";
    }
    else
    {
        $sql_select .= " join tblcategory as ca1 ON ca1.iId = ca.iParentId and ca1.cType='service' ";
    }
    $sql_select .= "   order by ca.iOrder ";
    if($limit>0)
    {
        $sql_select .= " limit $limit";
    }
    $rs         = $dbsql->query($sql_select);
    $rows       = $dbsql->num_rows($rs);
    $html_str   = '';
    $i          = 0;
    while($result = $dbsql->fetch_array($rs))
    {
        $img        = '<img src="'.GetIntroImg($result['cImage']).'" />';
        $url        = getLinkParentCat($result['iId']);
        $links      = getLinkContents($result['iId'],$url);
        if($i==$rows-1)
        {
            $html_str  .= '<div><a href="'.echoLink($url,false).'"><img src="'.echoLink(GetTextImg($result['cName']),false).'" border="0" /></a></div>';
            $html_str  .= getPackageService($result['iId'],$url);
            continue;
        }
        $html_str  .= '<table cellpadding="0" cellspacing="0">';
        $html_str  .= '<tr>';
        $html_str  .= '<td  width=220>'.(($i%2==0)? $img : $links).'</td>';
        $html_str  .= '<td><div class="svmsg">';
        $html_str  .= '<div class="'.(($i%2==0)? 'aleft': 'aright').'">';
        $html_str  .= '<a href="'.echoLink($url,false).'"><img src="'.echoLink(GetTextImg($result['cName']),false).'" border="0" /></a>';
        $html_str  .= '</div>';
        $html_str  .= ''.ParseText($result['cIntro']).'</div></td>';
        $html_str  .= '<td width=240 >'.(($i%2==1)? $img : $links).'</td>';
        $html_str  .= '<tr></table>';
        
        $i++;
    }
    return $html_str;
}

function getLinkContents($idP,$urlParent='')
{
    global $dbsql,$language;
    
    $idP     = intval($idP);
    if($idP <= 0)
    {
        return;   
    }
    
    $sql_select = "select cName,cUrlString,iId from tblcontent where iParentId= $idP order by iOrder";
    $rs         = $dbsql->query($sql_select);
    $html_str   = '';
    while($result   = $dbsql->fetch_array($rs))
    {
        $url        = $urlParent.'/'.$result['cUrlString'].'.htm';
        $html_str  .= '<a class="lcat" href="'.echoLink($url,false).'">'.$result['cName'].'</a>'; 
    }
    return $html_str;
    
}

function getPackageService($idP,$urlParent='')
{
    global $dbsql,$language;
    
    $idP     = intval($idP);
    if($idP <= 0)
    {
        return;   
    }
    $sql_select = "select cName,cUrlString,cDescription from tblcontent where iParentId = $idP order by iOrder limit 4";
    $rs         = $dbsql->query($sql_select);
    
    $html_str   = '<div class="packagehome">';
    while($result   = $dbsql->fetch_array($rs))
    {
        $url        = $urlParent.'/'.$result['cUrlString'].'.htm';
        $html_str  .= '<div class="box">';
        $html_str  .= '<a class="l" href="'.echoLink($url,false).'">'.$result['cName'].'</a>';
        $html_str  .= '<div>'.ParseText($result['cDescription']).'</div>';
        $html_str  .= '</div>'; 
    }
    $html_str  .= '</div>';
    return $html_str;
    
}